package com.hemh.utils;

import java.net.InetAddress;

/**
 * @author HeMingHui
 * @since 2020-10-18
 * @description 服务器的Util类
 */
public class ServerUtils {

	/**
	 * @author HeMingHui
	 * @since 2020-10-18
	 * @return String
	 * @description 返回服务器IP
	 */
	public static String getServerIP() {
		String serverIP = "";
		try {
			InetAddress addr = InetAddress.getLocalHost();
			serverIP = addr.getHostAddress();
			System.out.println("--->Local HostAddress:" + addr.getHostAddress());
			String hostname = addr.getHostName();
			System.out.println("--->Local host name: " + hostname);
		}catch(Exception e) {
			e.printStackTrace();
		}
		return serverIP;
	}
	
	/**
	 * @author HeMingHui
	 * @since 2020-10-18
	 * @return String
	 * @description 返回服务器名称
	 */
	public static String getServerName() {
		String serverName = "";		
		try {
			InetAddress addr = InetAddress.getLocalHost();
			serverName = addr.getHostName();;
		}catch(Exception e) {
			e.printStackTrace();
		}		
		return serverName;
	}
}
